#include <bits/stdc++.h>
using namespace std;

inline int read() {
	int x = 0, f = 0; char ch = getchar();
	while (ch < '0' or ch > '9') f |= (ch == '-'), ch = getchar();
	while (ch >= '0' and ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int __stk[128], __top;
inline void write(int x) {
    if(x < 0) putchar('-'), x = -x;
	do { __stk[++__top] = x % 10, x /= 10; } while (x);
	while (__top) putchar(__stk[__top--] + '0');
}

const int mod = 998244353;

void Min(int &x, int y) { y < x and (x = y); }
void Max(int &x, int y) { y > x and (x = y); }

void inc(int &x, int y) { (x += y) >= mod and (x -= mod); }
void mul(int &x, int y) { x = 1ll * x * y % mod; }

int q_pow(int x, int k) { int res = 1; for (; k; k >>= 1, mul(x, x)) if (k & 1) mul(res, x); return res; }

bool stmer;

const int N = 4e5 + 10;

int n, m, q, cnt;
int lat[N], Ans[N];

struct edge {
	int u, v;
} e[N];

vector<edge> op[N];
multiset<int> ans;

namespace LCT {
	#define ls(x) t[x][0]
	#define rs(x) t[x][1]

	int top;
	int stk[N], t[N][2], fa[N], s[N], val[N];
	
	bool vis[N], tag[N];

	bool nrt(int x) { return t[fa[x]][0] == x or t[fa[x]][1] == x; }
	int get(int x) { return t[fa[x]][1] == x;}

	bool cmp(int x, int y) { return val[x] < val[y]; }

	void update(int x) {
		s[x] = x;
		val[s[ls(x)]] > val[s[x]] ? s[x] = s[ls(x)] : 1;
		val[s[rs(x)]] > val[s[x]] ? s[x] = s[rs(x)] : 1;
	}

	void pushr(int x) { tag[x] ^= 1, swap(t[x][0], t[x][1]); }
	void pushdown(int x) { if (tag[x]) pushr(t[x][0]), pushr(t[x][1]), tag[x] = 0; }
	void rotate(int x) {
		int f1 = fa[x], f2 = fa[f1], k = get(x);
		if (nrt(f1)) t[f2][get(f1)] = x; fa[x] = f2;
		t[f1][k] = t[x][!k], fa[t[f1][k]] = f1, t[x][!k] = f1, fa[f1] = x;
		update(f1), update(x);
	}

	void splay(int x) {
		int p = x; stk[++top] = x;
		while (nrt(p)) stk[++top] = p = fa[p];
		while (top) pushdown(stk[top--]);
		for (int f = fa[x]; nrt(x); rotate(x), f = fa[x])
			if (nrt(f)) rotate(get(f) == get(x) ? f : x);
	}

	void access(int x) {
		int f = 0;
		while (x) splay(x), t[x][1] = f, update(x), f = x, x = fa[x];
	}

	void mkrt(int x) { access(x), splay(x), pushr(x); }
	int findrt(int x) {
		access(x), splay(x);
		while (t[x][0]) pushdown(x), x = t[x][0]; 
		return splay(x), x;
	}

	void link(int x,int y) { mkrt(x), fa[x] = y; }
	void cut(int x,int y) { mkrt(x), access(y), splay(y), fa[x] = t[y][0] = 0; }

	void merge(int p, int w) {
		if (vis[p]) {
			mkrt(p + n), ans.erase(ans.find(-val[p + n]));
			val[p + n] = w, update(p + n), ans.insert(-w); 
			return;
		}
		int x = e[p].u, y = e[p].v; mkrt(x), val[p + n] = w;
		if (findrt(y) ^ x) vis[p] = 1, link(x, p + n), link(p + n, y), cnt++, ans.insert(-w);
		else {
			access(y), splay(y); int z = s[y] - n;
			if (val[z + n] < w) return;
			cut(e[z].u, z + n), cut(e[z].v, z + n), vis[z] = 0;
			link(x, p + n), link(y, p + n), vis[p] = 1;
			ans.insert(-w), ans.erase(ans.find(-val[z + n]));
		}
	}
}

bool vis[N];

bool edmer;
signed main() {
	freopen("graph.in", "r", stdin);
	freopen("graph.out", "w", stdout);
	cerr << "[Memory] " << (&stmer - &edmer) / 1024 / 1024 << " MB\n";
    
	n = read(), m = read();
	for (int i = 1; i <= m; i++) e[i] = { read(), read() }, lat[i] = 1;

	q = read();
	for (int i = 1; i <= q; i++) {
		int k = read();
		if (m - k < n - 1) {
			vis[i] = 1; while (k--) read();
			continue;
		}
		while (k--) {
			int id = read();
			if (lat[id] < i) op[i - 1].push_back({ id, lat[id] });
			lat[id] = i + 1;
		}
	}
	for (int i = 1; i <= m; i++) if (lat[i] <= q) op[q].push_back({ i, lat[i] });

	for (int i = q; i; i--) {
		for (auto l : op[i]) LCT :: merge(l.u, l.v);
		if (!ans.empty() and !vis[i]) Ans[i] = (cnt == n - 1 and i + *ans.begin() >= 0);
	}

	for (int i = 1; i <= q; i++) puts(Ans[i] ? "YES" : "NO");

    cerr << "[Runtime] " << (double) clock() / CLOCKS_PER_SEC << " seconds\n";
	return 0;
} 